<template>

  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="直播间名称" prop="roomName">
      <el-input v-model="dataForm.roomName" placeholder="直播间名称"></el-input>
    </el-form-item>
    <el-form-item label="创建的医生id" prop="doctorId">
      <el-input v-model="dataForm.doctorId" placeholder="创建的医生id"></el-input>
    </el-form-item>
    <el-form-item label="直播间创建时间" prop="roomCreateTime">
      <el-input v-model="dataForm.roomCreateTime" placeholder="直播间创建时间"></el-input>
    </el-form-item>
    <el-form-item label="直播间标题" prop="roomTitle">
      <el-input v-model="dataForm.roomTitle" placeholder="直播间标题"></el-input>
    </el-form-item>
    <el-form-item label="直播间封面" prop="roomCoverImg">
      <el-input v-model="dataForm.roomCoverImg" placeholder="直播间封面"></el-input>
    </el-form-item>
    <el-form-item label="观看人数" prop="watchNum">
      <el-input v-model="dataForm.watchNum" placeholder="观看人数"></el-input>
    </el-form-item>
    <el-form-item label="医生名称" prop="doctorName">
      <el-input v-model="dataForm.doctorName" placeholder="医生名称"></el-input>
    </el-form-item>
    <el-form-item label="直播状态:   0:未开始   1:正在进行" prop="roomStatus">
      <el-input v-model="dataForm.roomStatus" placeholder="直播状态:   0:未开始   1:正在进行"></el-input>
    </el-form-item>
    <el-form-item label="隶属医院" prop="hospitalId">
      <el-input v-model="dataForm.hospitalId" placeholder="隶属医院"></el-input>
    </el-form-item>
    <el-form-item label="隶属科室" prop="departmentId">
      <el-input v-model="dataForm.departmentId" placeholder="隶属科室"></el-input>
    </el-form-item>
    <el-form-item label="预留01" prop="class01">
      <el-input v-model="dataForm.class01" placeholder="预留01"></el-input>
    </el-form-item>
    <el-form-item label="预留02" prop="class02">
      <el-input v-model="dataForm.class02" placeholder="预留02"></el-input>
    </el-form-item>
    <el-form-item label="预留03" prop="class03">
      <el-input v-model="dataForm.class03" placeholder="预留03"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>

</template>

<script>
  export default {
    data () {
      return {
          baseUrl: '',
        visible: false,
        dataForm: {
          id: 0,
          roomName: '',
          doctorId: '',
          roomCreateTime: '',
          roomTitle: '',
          roomCoverImg: '',
          watchNum: '',
          doctorName: '',
          roomStatus: '',
          hospitalId: '',
          departmentId: '',
          class01: '',
          class02: '',
          class03: ''
        },
        dataRule: {
          roomName: [
            { required: true, message: '直播间名称不能为空', trigger: 'blur' }
          ],
          doctorId: [
            { required: true, message: '创建的医生id不能为空', trigger: 'blur' }
          ],
          roomCreateTime: [
            { required: true, message: '直播间创建时间不能为空', trigger: 'blur' }
          ],
          roomTitle: [
            { required: true, message: '直播间标题不能为空', trigger: 'blur' }
          ],
          roomCoverImg: [
            { required: true, message: '直播间封面不能为空', trigger: 'blur' }
          ],
          watchNum: [
            { required: true, message: '观看人数不能为空', trigger: 'blur' }
          ],
          doctorName: [
            { required: true, message: '医生名称不能为空', trigger: 'blur' }
          ],
          roomStatus: [
            { required: true, message: '直播状态:   0:未开始   1:正在进行不能为空', trigger: 'blur' }
          ],
          hospitalId: [
            { required: true, message: '隶属医院不能为空', trigger: 'blur' }
          ],
          departmentId: [
            { required: true, message: '隶属科室不能为空', trigger: 'blur' }
          ],
          class01: [
            { required: true, message: '预留01不能为空', trigger: 'blur' }
          ],
          class02: [
            { required: true, message: '预留02不能为空', trigger: 'blur' }
          ],
          class03: [
            { required: true, message: '预留03不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
                      
        init (id) {
            this.dataForm.id = id || 0
            this.visible = true
            this.$nextTick(() => {
                this.$refs['dataForm'].resetFields()
                if (this.dataForm.id) {
                    axios.get(`${this.baseUrl}/roomLiving/livestreaming/info/${this.dataForm.id}`)
                    .then(({data}) => {
                        if (data && data.code === 0) {
                                                                                                                                            this.dataForm.roomName = data.liveStreaming.roomName
                                                                                                                this.dataForm.doctorId = data.liveStreaming.doctorId
                                                                                                                this.dataForm.roomCreateTime = data.liveStreaming.roomCreateTime
                                                                                                                this.dataForm.roomTitle = data.liveStreaming.roomTitle
                                                                                                                this.dataForm.roomCoverImg = data.liveStreaming.roomCoverImg
                                                                                                                this.dataForm.watchNum = data.liveStreaming.watchNum
                                                                                                                this.dataForm.doctorName = data.liveStreaming.doctorName
                                                                                                                this.dataForm.roomStatus = data.liveStreaming.roomStatus
                                                                                                                this.dataForm.hospitalId = data.liveStreaming.hospitalId
                                                                                                                this.dataForm.departmentId = data.liveStreaming.departmentId
                                                                                                                this.dataForm.class01 = data.liveStreaming.class01
                                                                                                                this.dataForm.class02 = data.liveStreaming.class02
                                                                                                                this.dataForm.class03 = data.liveStreaming.class03
                                                                                }
                    })
                }
            })
        },


      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            axios.post(`${this.baseUrl}/roomLiving/livestreaming/${!this.dataForm.id ? 'save' : 'update'}`)
            .then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }


    }
  }
</script>
